<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_content
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');

JHtml::_('behavior.framework');

// Create some shortcuts.
$params		= &$this->item->params;
$n			= count($this->items);
$listOrder	= $this->escape($this->state->get('list.ordering'));
$listDirn	= $this->escape($this->state->get('list.direction'));

// check for at least one editable article
$isEditable = false;
if (!empty($this->items))
{
	foreach ($this->items as $article)
	{
		if ($article->params->get('access-edit'))
		{
			$isEditable = true;
			break;
		}
	}
}

?>

<div class="container noticias">
	
	<?php 
		$obj = null;
		foreach ($this->items as $item) :
			$obj = $item;
		endforeach;
		
		if(isset($obj)):		
			if($this->escape($obj->category_title) == 'NotÃ­cias') :  
				echo "<h3>Últimas Notícias</h3>";
			else:
				echo "<h3>".$this->escape($obj->category_title)."</h3>";
			endif;
		endif;
	
	?>
	<div id="menuinterno"></div>
	
	<?php 
		
	if(isset($obj)):		
		if($this->escape($obj->category_title) == 'NotÃ­cias') :  ?>
		<ul class="noticia">	
		<?php 
			$data='';
			$i=0;
			foreach ($this->items as $item) :  
				$hora = substr($item->publish_up, 11, 5);
				
				if($data != substr($item->publish_up, 0, 10)):		
					echo '<li class="data ';
					if($i==0):
						echo 'outros1 ';
					else:
						echo ' outros ';
					endif;
					echo '">' . getDateMyFormat(substr($item->publish_up, 0, 10)) . '</li>';
					
				endif;
				
				echo '<li><span>'. $hora .'</span><a href="' . JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid)) . '" title="'.$item->title.'" >'.$item->title.'</a></li>';
				
				$data = substr($item->publish_up, 0, 10);
				$i++;
			endforeach;
		
		
		?>
	
	</ul>
	<?php 
		else:		
			$strHtml ='<div class="camaraintinerante">';
			$strHtml .=  $this->category->description;
			$strHtml .= "<ul>";
			
			foreach ($this->items as $item) :
			
				list($ano, $mes, $dia) = explode('-', $item->publish_up);
				
				$dia = substr($dia, 0,2);
				$strHtml .= '<li>
						<a href="' . JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid)) . '" title="'.$item->title.'" >'.$item->title.'</a>
					<span class="data">'.$dia.'/'.$mes.'/'.$ano.'</span>	
				</li>';
			
				
			endforeach;
			
			$strHtml .= "</ul>";
			$strHtml .="</div>";
			echo $strHtml;
		endif;
	endif;
	?>
	



<?php // Add pagination links ?>
<?php if (!empty($this->items)) : ?>
	<?php if (($this->params->def('show_pagination', 2) == 1  || ($this->params->get('show_pagination') == 2)) && ($this->pagination->pagesTotal > 1)) : ?>
	<div class="pagination">
		
		<div class="btnback">
			<a href="javascript:window.history.back()" title="Voltar à página anterior" ><img src="<?php echo JUri::base() ?>templates/cmmacae/img/btnBack.jpg" /></a>
		</div>
		
		<div class="pag">
		<?php if ($this->params->def('show_pagination_results', 1)) : ?>
			<p class="counter pull-right">
				<?php echo $this->pagination->getPagesCounter(); ?> - 
			</p>
		<?php endif; ?>
		<?php echo $this->pagination->getPagesLinks(); ?>
		</div>
	</div>
	<?php endif; ?>

<?php  endif; ?>

</div>

<?php 

function getDateMyFormat($value) 
{
	$arrSemana = array('Domingo','Segunda-Feira','Terça-Feira','Quarta-Feira','Quinta-Feira','Sexta-Feira','Sábado');
	$arrMes = array('Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro');
	$dia = date("d", strtotime($value));
	$ano = date("Y", strtotime($value));
	$mes = date("m", strtotime($value));
	$semana = date("w", strtotime($value));

	$html = '';
	if(date('Y-m-d')==$value)
		$html .='Hoje - ';
	$html .= $arrSemana[$semana] . ' - ' . $dia . ' de ' . $arrMes[intval($mes)-1] . ' de ' . $ano;
	
	return $html;
}
?>